#!/usr/bin/env bash
set -ex

cd $(dirname $0)/..

source ./scripts/version.sh

DOCKER_BUILDKIT=${DOCKER_BUILDKIT:-1} docker image build \
    --build-arg TAG=${VERSION} \
    --build-arg KUBERNETES_VERSION=${KUBERNETES_VERSION} \
    --build-arg MAJOR=${VERSION_MAJOR} \
    --build-arg MINOR=${VERSION_MINOR} \
    --build-arg CACHEBUST="$(date +%s%N)" \
    --tag ${REPO}/${PROG}-runtime:${DOCKERIZED_VERSION} \
    --tag ${REPO}/${PROG}-runtime:${DOCKERIZED_VERSION}-${GOOS}-${GOARCH} \
    --target runtime \
    --file Dockerfile \
    .

DOCKER_BUILDKIT=${DOCKER_BUILDKIT:-1} docker image build \
    --build-arg TAG=${VERSION} \
    --build-arg KUBERNETES_VERSION=${KUBERNETES_VERSION} \
    --build-arg MAJOR=${VERSION_MAJOR} \
    --build-arg MINOR=${VERSION_MINOR} \
    --build-arg CACHEBUST="$(date +%s%N)" \
    --tag ${REPO}/${PROG}-runtime:${DOCKERIZED_VERSION}-windows-amd64 \
    --target windows-runtime \
    --file Dockerfile.windows \
    .

mkdir -p build/images
docker image save \
    --output build/images/${PROG}-runtime.tar \
    ${REPO}/${PROG}-runtime:${DOCKERIZED_VERSION}-${GOOS}-${GOARCH}
